define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'oil/invoice/index' + location.search,
                    add_url: 'oil/invoice/add',
                    edit_url: 'oil/invoice/edit',
                    del_url: 'oil/invoice/del',
                    multi_url: 'oil/invoice/multi',
                    import_url: 'oil/invoice/import',
                    table: 'oil_invoice',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'type', title: __('Type'),searchList: {"1":__('Type 1'),"2":__('Type 2')},formatter: Table.api.formatter.label},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'header_type', title: __('Header_type'),searchList: {"1":__('Header_type 1'),"2":__('Header_type 2')},formatter: Table.api.formatter.label},
                        {field: 'header_title', title: __('Header_title'), operate: 'LIKE'},
                        {field: 'header_num', title: __('Header_num'), operate: 'LIKE'},
                        {field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'company_address', title: __('Company_address'), operate: 'LIKE'},
                        {field: 'company_phone', title: __('Company_phone'), operate: 'LIKE'},
                        {field: 'company_bank', title: __('Company_bank'), operate: 'LIKE'},
                        {field: 'company_bank_num', title: __('Company_bank_num'), operate: 'LIKE'},
                        {field: 'memo', title: __('Memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 're_times', title: __('Re_times')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'is_need_send', title: __('Is_need_send'),searchList: {"0":__('Is_need_send 0'),"1":__('Is_need_send 1')},formatter: Table.api.formatter.label},
                        {field: 'status', title: __('Status'),searchList: {'normal':__('Status Normal'),'finish':__('Status Finish'),'again':__('Status Again'),'again_finish':__('Status Again_finish')},formatter: Table.api.formatter.label},
                        {field: 'order_ids', title: __('Order_ids'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
